package com.hznu.ucenter.controller;


import com.hznu.commonutils.R;
import com.hznu.ucenter.entity.Msg;
import com.hznu.ucenter.entity.Rsu;
import com.hznu.ucenter.entity.Vehicle;
import com.hznu.ucenter.service.RsuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cdd
 * @since 2021-04-02
 */
@RestController
@RequestMapping("/rsu")
public class RsuController {

    @Autowired
    private RsuService rsuService;

    // rsu列表
    @GetMapping("getRsuList")
    public R getRsuList() {
        List<Rsu> rsu = rsuService.getRsuList();
        return R.ok().data("rsu",rsu);
    }

    // 显示范围内的车辆
    @GetMapping("getCarInside/{rsuId}")
    public R getCarInside(@PathVariable Integer rsuId) {
        List<Vehicle> cars = rsuService.getCarInside(rsuId);
        return R.ok().data("cars",cars);
    }

    // 显示RSU内存储的信息，需要用到redis了
    @GetMapping("getRsuMsg/{rsuId}")
    public R getRsuMsg(@PathVariable int rsuId) {
        List<Msg> msgs = rsuService.getMsgListByRsuId(rsuId);
        return R.ok().data("msgs",msgs);
    }

    // 添加RSU
    @PostMapping("addRsu")
    public R addRsu(@RequestBody Rsu rsu) {
        rsuService.addRsu(rsu);
        return R.ok();
    }

    // 删除Rsu
    @GetMapping("deleteRsu/{rsuId}")
    public R deleteRsu(@PathVariable int rsuId) {
        rsuService.deleteRsu(rsuId);
        return R.ok();
    }
}

